package com.aizhixin.lab.statistics.service;

import com.aizhixin.lab.statistics.entity.CourseData;
import com.aizhixin.lab.statistics.repository.CourseDataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class CourseDataService {

    @Autowired
    private CourseDataRepository courseDataRepository;

    public void GiveLessonsNum(String courseId){
        CourseData courseData = courseDataRepository.findByCourseId(courseId);
        if (Objects.isNull(courseData)){
            courseData=new CourseData();
            courseData.setStudentStudyNum(0);
            courseData.setGiveLessonsNum(courseData.getGiveLessonsNum()+1);
        }else {
            courseData.setGiveLessonsNum(courseData.getGiveLessonsNum()+1);
        }
        courseDataRepository.save(courseData);
    }
    public void studentStudyNum(String courseId){
        CourseData courseData = courseDataRepository.findByCourseId(courseId);
        if (Objects.isNull(courseData)){
            courseData=new CourseData();
            courseData.setGiveLessonsNum(courseData.getGiveLessonsNum()+1);
        }else {
            courseData.setGiveLessonsNum(courseData.getGiveLessonsNum()+1);
        }
        courseDataRepository.save(courseData);
    }

}
